﻿using System.Windows;
using System.Windows.Controls;

namespace HuiZe.education.Resource.Controls
{
    public class CheckListItem : ListBoxItem
    {
        public bool IsChecked
        {
            get { return (bool)GetValue(IsCheckedProperty); }
            set { SetValue(IsCheckedProperty, value); }
        }

        public static readonly DependencyProperty IsCheckedProperty =
            DependencyProperty.Register("IsChecked", typeof(bool), typeof(CheckListItem), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnChanged)));

        private static void OnChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CheckListItem obj = d as CheckListItem;
            if (obj != null)
                obj.OnCheckedChanged();
        }
        private void OnCheckedChanged()
        {
            RoutedEventArgs args = new RoutedEventArgs(CheckedChangedEvent, this);
            RaiseEvent(args);
        }

        public static readonly RoutedEvent CheckedChangedEvent = EventManager.RegisterRoutedEvent("CheckedChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(CheckListItem));
        public event RoutedEventHandler CheckedChanged
        {
            add
            {
                AddHandler(CheckedChangedEvent, value);
            }
            remove
            {
                RemoveHandler(CheckedChangedEvent, value);
            }
        }

    }
}
